## Estimate the AMCEs for technocratic democracy and merge them to the main data frame
amces_techno <- cj(data = df_no_techno_ties,
formula = as.formula(paste("selected ~", attributes)),
id = ~id,
estimate = "amce")
amces[22:24, 5:10] <- amces_techno[22:24, 5:10]
## Estimate the AMCEs for direct democracy and merge them to the main data frame
amces_direct <- cj(data = df_no_direct_ties,
formula = as.formula(paste("selected ~", attributes)),
id = ~id,
estimate = "amce")
amces[25:27, 5:10] <- amces_direct[25:27, 5:10]
## Create a function that indicates which estimates are statistically significant
## at the 5% level after using the BH procedure to adjust for multiple comparisons
sig1_fun <- function(data){
data <- data %>%
mutate(sig = case_when(
(p.adjust(p, method = "BH") < 0.05) == TRUE ~ 1,
(p.adjust(p, method = "BH") < 0.05) == FALSE ~ 0)) %>%
mutate(sig = factor(sig, levels = c(0, 1)))
return(data)
}
## Apply the function to adjust for multiple comparisons
amces <- sig1_fun(amces)
amces$sig[is.na(amces$sig)] <- 0
## Visualize the AMCEs
p <- plot(amces, legend_pos = "none", size = 1) +
aes(color = sig) +
xlab("Effect on Pr(Being Selected as More Democratic)")
p <- p + scale_color_manual(values = c("grey60", "black"))
p <- p + theme_bw(base_size = 10, base_family = "Times") %+replace%
theme(
axis.text.x = element_text(size = 9, colour = "black",  hjust = .5, vjust = 1),
axis.text.y = element_text(size = 9, colour = "black", hjust = 1, vjust = .5, face = bph),
axis.ticks = element_line(colour = "grey50"),
axis.title.y = element_text(size = 9, angle = 90, vjust = .01, hjust = .1),
legend.position = "none",
strip.text.x = element_text(size = 8),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
p_amce <- p + coord_cartesian(xlim = c(-0.03, 0.27))
### Figure SXXB: attribute salience with the six-country sample after removing ties for each attribute ----
## Estimate the salience score of electoral democracy
# Reshape data
df_salience_election <- df_no_election_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score
salience_election <- df_salience_election %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience <- salience_election
## Estimate the salience score of liberal democracy
# Reshape data
df_salience_liberal <- df_no_liberal_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_liberal <- df_salience_liberal %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[1, 2] <- salience_liberal[1, 2]
## Estimate the salience score of institutional democracy
# Reshape data
df_salience_institution <- df_no_institution_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_institution <- df_salience_institution %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[7, 2] <- salience_institution[7, 2]
## Estimate the salience score of populist democracy
# Reshape data
df_salience_populist <- df_no_populist_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_populist <- df_salience_populist %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[9, 2] <- salience_institution[9, 2]
## Estimate the salience score of loyalist democracy
# Reshape data
df_salience_loyalist <- df_no_loyalist_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_loyalist <- df_salience_loyalist %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[8, 2] <- salience_institution[8, 2]
## Estimate the salience score of substantive democracy (economy)
# Reshape data
df_salience_economy <- df_no_economy_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_economy <- df_salience_economy %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[3, 2] <- salience_economy[3, 2]
## Estimate the salience score of substantive democracy (gender)
# Reshape data
df_salience_gender <- df_no_gender_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_gender <- df_salience_gender %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[6, 2] <- salience_gender[6, 2]
## Estimate the salience score of technocratic democracy
# Reshape data
df_salience_techno <- df_no_techno_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_techno <- df_salience_techno %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[5, 2] <- salience_techno[5, 2]
## Estimate the salience score of direct democracy
# Reshape data
df_salience_direct <- df_no_direct_ties %>%
mutate_if(is.factor, as.character) %>%
gather("attribute", "level", 3:11)
# Calculate the salience score and merge it to the main data frame
salience_direct <- df_salience_direct %>%
group_by(attribute, level) %>%
summarize(average = mean(selected)) %>%
ungroup() %>%
mutate(deviation = abs(average - 0.5)) %>%
group_by(attribute) %>%
summarize(salience_mean = mean(deviation))
salience[2, 2] <- salience_direct[2, 2]
## Visualize the estimates
# Rename the attributes
salience$attribute <-
case_match(salience$attribute,
"election" ~ "Electoral\nDemocracy",
"civil" ~ "Liberal\nDemocracy",
"leader" ~ "Institutional\nDemocracy",
"populist" ~ "Populist\nDemocracy",
"obedient" ~ "Loyalist\nDemocracy",
"econ" ~ "Substantive\nDemocracy\n(Economy)",
"gender" ~ "Substantive\nDemocracy\n(Gender)",
"expert" ~ "Technocratic\nDemocracy",
"direct" ~ "Direct\nDemocracy")
# Reorder the attributes
salience$attribute <-
factor(salience$attribute,
levels = c("Electoral\nDemocracy",
"Liberal\nDemocracy",
"Institutional\nDemocracy",
"Populist\nDemocracy",
"Loyalist\nDemocracy",
"Substantive\nDemocracy\n(Economy)",
"Substantive\nDemocracy\n(Gender)",
"Technocratic\nDemocracy",
"Direct\nDemocracy"))
p_salience <- ggplot(data = salience) +
geom_point(aes(x = fct_rev(attribute), y = salience_mean),
size = 2, shape = 8) +
coord_flip(ylim = c(0, 0.1)) +
labs(y = "Attribute Salience", x = NULL) +
theme_bw(base_size = 10, base_family = "Times") %+replace%
theme(
axis.text.x = element_text(size = 9, colour = "black", hjust = .5, vjust = 1),
axis.text.y = element_text(size = 9, colour = "black", face = "bold", hjust = 1, vjust = .5),
axis.ticks = element_line(colour = "grey50"),
strip.text.x = element_text(size = 9),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
## Combine the plot with the aggregate AMCE plot
p_amce <- p_amce + ggtitle("Estimated AMCEs") +
theme(plot.title = element_text(hjust = 0.5, size = 11, face = "italic"))
p_salience <- p_salience + ggtitle("Attribute Salience") +
theme(plot.title = element_text(hjust = 0.5, size = 11, face = "italic"))
plot_grid(p_amce, p_salience, labels = "AUTO", nrow = 1,
label_fontfamily = "Times", label_size = 11,
rel_widths = c(2, 1))
ggsave("Figure SXX.pdf", width = 8, height = 6)
p_salience + scale_x_continuous(breaks = c(0, 0.03, 0.06, 0.09))
p_salience + scale_x_continuous(n.breaks = 5)
p_salience + scale_x_discrete(n.breaks = 5)
?scale_x_discrete
p_salience + scale_x_discrete(breaks = c(0, 0.03))
p_salience <- ggplot(data = salience) +
geom_point(aes(x = fct_rev(attribute), y = salience_mean),
size = 2, shape = 8) +
coord_flip(ylim = c(0, 0.1)) +
labs(y = "Attribute Salience", x = NULL) +
scale_y_continuous(n.breaks = 5)
p_salience <- ggplot(data = salience) +
geom_point(aes(x = fct_rev(attribute), y = salience_mean),
size = 2, shape = 8) +
coord_flip(ylim = c(0, 0.1)) +
labs(y = "Attribute Salience", x = NULL) +
scale_y_continuous(n.breaks = 3) +
theme_bw(base_size = 10, base_family = "Times") %+replace%
theme(
axis.text.x = element_text(size = 9, colour = "black", hjust = .5, vjust = 1),
axis.text.y = element_text(size = 9, colour = "black", face = "bold", hjust = 1, vjust = .5),
axis.ticks = element_line(colour = "grey50"),
strip.text.x = element_text(size = 9),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
## Combine the plot with the aggregate AMCE plot
p_amce <- p_amce + ggtitle("Estimated AMCEs") +
theme(plot.title = element_text(hjust = 0.5, size = 11, face = "italic"))
p_salience <- p_salience + ggtitle("Attribute Salience") +
theme(plot.title = element_text(hjust = 0.5, size = 11, face = "italic"))
plot_grid(p_amce, p_salience, labels = "AUTO", nrow = 1,
label_fontfamily = "Times", label_size = 11,
rel_widths = c(2, 1))
plot_grid(p_amce, p_salience, labels = "AUTO", nrow = 1,
label_fontfamily = "Times", label_size = 11,
rel_widths = c(2, 1))
ggsave("Figure SXX.pdf", width = 8, height = 6)
####################################################################################################
### Title: People Consistently View Elections and Civil Liberties as Key Components of Democracy ###
### Content: Sample demographics (Table S4)                                                      ###
### Date: August 13, 2024                                                                        ###
####################################################################################################
### Set-up ----
## Clean the working environment and set the working directory
rm(list = ls())
setwd("~/Desktop/Science_Replication/demographics")
## Install the cjdata package (if not yet installed)
# library(devtools)  # version 2.4.3
# install_github(repo = "yhoriuchi/cjdata")
## Load the required packages
library(tidyverse) # version 2.0.0
library(cjdata)    # version 0.1.0
## Read the raw datasets
df_US <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_US.csv")
df_IT <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_IT.csv")
df_EG <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_EG.csv")
df_IN <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_IN.csv")
df_TH <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_TH.csv")
df_JP <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_JP.csv")
1008+1022+1047+1012+1037+1024
## Thailand
mean(df_TH$democracy_impt_1, na.rm = T)
####################################################################################################
### Title: People Consistently View Elections and Civil Liberties as Key Components of Democracy ###
### Content: Main analysis                                                                       ###
### Date: August 13, 2024                                                                        ###
####################################################################################################
### Set-up ----
## Clean the working environment and set the working directory
rm(list = ls())
setwd("~/Desktop/Science_Replication/all_countries")
## Load the required packages
library(ggplot2)         # version 3.4.3
library(tidyverse)       # version 2.0.0
library(estimatr)        # version 1.0.0
library(cregg)           # version 0.4.0
library(expss)           # version 0.11.4
library(ggrepel)         # version 0.9.1
library(cowplot)         # version 1.1.1
library(survey)          # version 4.1.1
library(marginaleffects) # version 0.18.0
library(modelsummary)    # version 0.9.4
library(texreg)          # version 1.37.5
## Read the cleaned datasets
df_US <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_US.csv")
df_JP <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_JP.csv")
df_EG <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_EG.csv")
df_IN <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_IN.csv")
df_IT <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_IT.csv")
df_TH <- read.csv("~/Desktop/Science_Replication/data_cleaning/df_TH.csv")
## Merge the datasets
df_cj <- bind_rows(df_US, df_JP, df_EG, df_IN, df_IT, df_TH)
## Reorder the factors
reorder_levels <- function(df_cj){
# Electoral democracy
df_cj$election <-
factor(df_cj$election,
levels = c("Elections are not held", "Elections are biased", "Elections are free and fair"))
# Liberal democracy
df_cj$civil <-
factor(df_cj$civil,
levels = c("Civil liberties are not at all protected", "Civil liberties are weakly protected", "Civil liberties are strongly protected"))
# Institutional democracy
df_cj$leader <-
factor(df_cj$leader,
levels = c("Leader is rarely constrained", "Leader is sometimes constrained", "Leader is frequently constrained"))
# Populist democracy
df_cj$populist <-
factor(df_cj$populist,
levels = c("Leader rarely follows the majority", "Leader sometimes follows the majority", "Leader frequently follows the majority"))
# Loyalist democracy
df_cj$obedient <-
factor(df_cj$obedient,
levels = c("Dissidents mostly challenge the gov't", "Dissidents occasionally obey the gov't", "Dissidents mostly obey the gov't"))
# Substantive democracy - economy
df_cj$econ <-
factor(df_cj$econ,
levels = c("Economic equality is very low", "Economic equality is somewhat low", "Economic equality is high"))
# Substantive democracy - gender
df_cj$gender <-
factor(df_cj$gender,
levels = c("Gender equality is very low", "Gender equality is somewhat low", "Gender equality is high"))
# Technocratic democracy
df_cj$expert <-
factor(df_cj$expert,
levels = c("Experts have small influence on policy", "Experts have some influence on policy", "Experts have much influence on policy"))
# Direct democracy
df_cj$direct <-
factor(df_cj$direct,
levels = c("Policies are rarely voted on", "Policies are sometimes voted on", "Policies are frequently voted on"))
return(df_cj)
}
df_cj <- reorder_levels(df_cj)
# Country
df_cj$country <- factor(df_cj$country,
levels = c("US", "JP", "EG", "IN", "IT", "TH"),
labels = c("United States", "Japan", "Egypt", "India", "Italy", "Thailand"))
## Check if there are complete ties (i.e., ALL attribute-levels are the same for a country pair)
## and remove them if exist
# Identify ties
df_cj$id.task <- paste0(df_cj$id, ".", df_cj$task)
df_wide <- df_cj %>% dplyr::select(id.task, profile, election, civil, leader, populist, obedient, econ, gender, expert, direct)
df_wide <- reshape(df_wide, idvar = "id.task", timevar = "profile", direction = "wide")
df_wide$tie <-
ifelse((df_wide$election.1 == df_wide$election.2) &
(df_wide$civil.1 == df_wide$civil.2) &
(df_wide$leader.1 == df_wide$leader.2) &
(df_wide$populist.1 == df_wide$populist.2) &
(df_wide$obedient.1 == df_wide$obedient.2) &
(df_wide$econ.1 == df_wide$econ.2) &
(df_wide$gender.1 == df_wide$gender.2) &
(df_wide$expert.1 == df_wide$expert.2) &
(df_wide$direct.1 == df_wide$direct.2),
1, 0)
table(df_wide$tie)
temp <- subset(df_wide, tie == 1) # respondent id = R_3RjV1QPR72JSMjA; task = 1
# Remove the complete tie
df_cj <- subset(df_cj, id.task != "R_3RjV1QPR72JSMjA.1")
df_TH <- subset(df_TH, id != "R_3RjV1QPR72JSMjA" | task != 1)
### Figure 1A: AMCEs with the six-country sample ----
## Format attribute labels in plots
df_cj <- apply_labels(df_cj,
election = "Electoral Democracy",
civil = "Liberal Democracy",
leader = "Institutional Democracy",
populist = "Populist Democracy",
obedient = "Loyalist Democracy",
econ = "Substantive Democracy - Economy",
gender = "Substantive Democracy - Gender",
expert = "Technocratic Democracy",
direct = "Direct Democracy")
attributes <- "election + civil + leader + populist + obedient + econ + gender + expert + direct"
## Bold feature labels in plots
bph <- c('bold', rep('plain', 3), 'bold', rep('plain', 3),
'bold', rep('plain', 3), 'bold', rep('plain', 3),
'bold', rep('plain', 3), 'bold', rep('plain', 3),
'bold', rep('plain', 3), 'bold', rep('plain', 3),
'bold', rep('plain', 3)) %>%
rev() # reverse coding
## Create a function that indicates which estimates are statistically significant
## at the 5% level after using the BH procedure to adjust for multiple comparisons
sig1_fun <- function(data){
data <- data %>%
mutate(sig = case_when(
(p.adjust(p, method = "BH") < 0.05) == TRUE ~ 1,
(p.adjust(p, method = "BH") < 0.05) == FALSE ~ 0)) %>%
mutate(sig = factor(sig, levels = c(0, 1)))
return(data)
}
### Figure S2: AMCEs based on democratic ratings ----
## Create an outcome variable that indicates the respondent's rating of a given country
df_cj <- df_cj %>% mutate(dem_rating = case_when(
task == 1 & profile == 1 ~ Q1.2,
task == 1 & profile == 2 ~ Q1.3,
task == 2 & profile == 1 ~ Q1.6,
task == 2 & profile == 2 ~ Q1.7,
task == 3 & profile == 1 ~ Q1.10,
task == 3 & profile == 2 ~ Q1.11
))
p <- plot(amces, legend_pos = "none", size = 1) +
aes(color = sig) +
xlab("Effect on Democratic Rating")
## Estimate the aggregate AMCEs and visualize them
amces <- cj(data = df_cj,
formula = as.formula(paste("dem_rating ~", attributes)),
id = ~id,
estimate = "amce")
amces <- sig1_fun(amces)
p <- plot(amces, legend_pos = "none", size = 1) +
aes(color = sig) +
xlab("Effect on Democratic Rating")
p <- p + scale_color_manual(values = c("grey60", "black"))
p <- p + theme_bw(base_size = 8, base_family = "Times") %+replace%
theme(
axis.text.x = element_text(size = 6, colour = "black",  hjust = .5, vjust = 1),
axis.text.y = element_text(size = 8, colour = "black", hjust = 1, vjust = .5, face = bph),
axis.ticks = element_line(colour = "grey50"),
axis.title.y = element_text(size = 10, angle = 90, vjust = .01, hjust = .1),
legend.position = "none",
strip.text.x = element_text(size = 8),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
p <- p + coord_cartesian(xlim = c(-0.3, 0.9))
p
p <- p + coord_cartesian(xlim = c(-0.2, 1))
p
ggsave("Figure S2_aggregate.pdf", width = 6, height = 6)
p <- p + coord_cartesian(xlim = c(-0.2, 0.9))
ggsave("Figure S2_aggregate.pdf", width = 6, height = 4)
p <- p + coord_cartesian(xlim = c(-0.15, 0.9))
ggsave("Figure S2_aggregate.pdf", width = 6, height = 4)
p <- plot(amces, legend_pos = "none", size = 1) +
aes(color = sig) +
xlab("Effect on Democratic Rating")
p <- p + scale_color_manual(values = c("grey60", "black"))
p <- p + theme_bw(base_size = 8, base_family = "Times") %+replace%
theme(
axis.text.x = element_text(size = 8, colour = "black",  hjust = .5, vjust = 1),
axis.text.y = element_text(size = 8, colour = "black", hjust = 1, vjust = .5, face = bph),
axis.ticks = element_line(colour = "grey50"),
axis.title.y = element_text(size = 10, angle = 90, vjust = .01, hjust = .1),
legend.position = "none",
strip.text.x = element_text(size = 8),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
p <- p + coord_cartesian(xlim = c(-0.15, 0.9))
ggsave("Figure S2_aggregate.pdf", width = 6, height = 4)
####################################################################################################
### Title: People Consistently View Elections and Civil Liberties as Key Components of Democracy ###
### Content: Sample demographics (Table S4)                                                      ###
### Date: August 13, 2024                                                                        ###
####################################################################################################
### Set-up ----
## Clean the working environment and set the working directory
rm(list = ls())
setwd("~/Desktop/Science_Replication/demographics")
## Install the cjdata package (if not yet installed)
# library(devtools)  # version 2.4.3
# install_github(repo = "yhoriuchi/cjdata")
## Load the required packages
library(tidyverse) # version 2.0.0
library(cjdata)    # version 0.1.0
## Read the raw datasets
df_US <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_US.csv")
df_IT <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_IT.csv")
df_EG <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_EG.csv")
df_IN <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_IN.csv")
df_TH <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_TH.csv")
df_JP <- read_Qualtrics("~/Desktop/Science_Replication/data_cleaning/raw_JP.csv")
### Age ----
## The United States
summary(df_US$age)
### Age ----
## The United States
mean(df_US$age)
sd(df_US$age)
?sd
## Italy
mean(df_IT$age)
sd(df_IT$age)
## Egypt
mean(df_EG$age)
sd(df_EG$age)
## India
mean(df_IN$age)
sd(df_IN$age)
## Thailand
mean(df_TH$age)
sd(df_TH$age)
## Japan
mean(df_JP$age)
sd(df_JP$age)
